<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class Agreement extends Frontend
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        $type = $this->request->param('type', 'user_agreement');
        $allowTypes = ['user_agreement', 'about_us','privacy_policy'];
        
        if (!in_array($type, $allowTypes)) {
            $this->error('不支持的配置类型');
        }
        
        $content = Db::name('config')
            ->where('name', $type)
            ->value('value');
            
        if (!$content) {
            $this->error('配置不存在');
        }
        $typetext = '用户协议';
        if($type == 'privacy_policy'){
            $typetext = '隐私政策';
        }
        if($type == 'about_us'){
            $typetext = '关于我们';
        }
        $this->assign([
            'content' => $content,
            'title' => $typetext
        ]);
        return $this->view->fetch();
    }
}